package rullekake.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * Utbytteklasse.
 * Holder på alle data og relasjonsinformasjon for utbytter. Består av set/get for alt + equals, hashcode og toString.
 *
 */
@Entity
@Table(name = "OUTCOME")
@NamedQueries({
    @NamedQuery(name = "Outcome.findAll", query = "SELECT o FROM Outcome o"),
    @NamedQuery(name = "Outcome.findByOutcomeId", query = "SELECT o FROM Outcome o WHERE o.outcomeId = :outcomeId"),
    @NamedQuery(name = "Outcome.findByOutcomeType", query = "SELECT o FROM Outcome o WHERE o.outcomeType = :outcomeType"),
    @NamedQuery(name = "Outcome.findByCourse", query = "SELECT o FROM Outcome o WHERE o.course = :course")})
public class Outcome implements Serializable {
    private static final long serialVersionUID = 1L;
    public static final short KNOWLEDGE = 1;
    public static final short SKILL = 2;
    public static final short GENERAL_COMPETENCE = 3;

    public static String getTypeFromInt(Short outcomeType) {
        if (outcomeType == 1) return "Knowledge";
        if (outcomeType == 2) return "Skill";
        return "General Competence";
    }
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "OUTCOME_ID")
    private Integer outcomeId;
    @Lob
    @Column(name = "TEXT")
    private String text;
    @Lob
    @Column(name = "TEXT_NO")
    private String textNo;
    @Column(name = "OUTCOME_TYPE")
    private Short outcomeType;
    @JoinColumn(name = "COURSE_ID", referencedColumnName = "COURSE_ID")
    @ManyToOne(optional = false)
    private Course course;

    public Outcome() {
    }

    public Outcome(Integer outcomeId) {
        this.outcomeId = outcomeId;
    }

    public Integer getOutcomeId() {
        return outcomeId;
    }

    public void setOutcomeId(Integer outcomeId) {
        this.outcomeId = outcomeId;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getTextNo() {
        return textNo;
    }

    public void setTextNo(String textNo) {
        this.textNo = textNo;
    }

    public Short getOutcomeType() {
        return outcomeType;
    }

    public void setOutcomeType(Short outcomeType) {
        this.outcomeType = outcomeType;
    }

    public Course getCourse() {
        return course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (outcomeId != null ? outcomeId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Outcome)) {
            return false;
        }
        Outcome other = (Outcome) object;
        if ((this.outcomeId == null && other.outcomeId != null) || (this.outcomeId != null && !this.outcomeId.equals(other.outcomeId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "rullekake.entities.Outcome[outcomeId=" + outcomeId + "]";
    }

}
